home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / shells / zsh-3.0-p / zsh-3 / zsh-3.0-pre3 / Etc / FAQ < prev    next >
Text File  |  1996-07-15  |  61KB  |  1,272 lines

  1. Archive-Name: unix-faq/shell/zsh
  2. Last-Modified: 1996/06/26
  3. Submitted-By: pws@amtp.liv.ac.uk (Peter Stephenson)
  4. Version: $Id: FAQ,v 2.15 1996/06/26 07:15:21 pws Exp $
  5. Frequency: Monthly
  6. Copyright: (C) P.W. Stephenson, 1995, 1996 (see end of document)
  7.  
  8. Changes since last issue:
  9. - in A4: new beta version
  10. - in A5: updated archive list
  11. - in A6: extended 'exec zsh' for login files from Bart Schaefer
  12. - in B1: added more prominent note on word splitting; other entries updated
  13. - in C1: mention globbing
  14. - in Z1: <> now does redirection, not numeric globbing. *NB!*,
  15.          exec, noglob etc. behaviour changed
  16.  
  17. This document contains a list of frequently-asked (or otherwise
  18. significant) questions concerning the Z-shell, a command interpreter for
  19. many UNIX systems which is freely available to anyone with FTP access.
  20. In fact, zsh is currently the most powerful freely available shell.
  21.  
  22. If you have never heard of `sh', `csh' or `ksh', then you are probably
  23. better off to start by reading a general introduction to UNIX rather
  24. than this document.
  25.  
  26. If you just want to know how to get your hands on the latest version,
  27. skip to question A5); if you want to know what to do with insoluble
  28. problems, go to Z2).
  29.  
  30. Notation: Quotes `like this' are ordinary textual quotation
  31. marks.  Other uses of quotation marks are input to the shell.
  32.  
  33. Contents:
  34. Section A:  Introducing zsh and how to install it
  35. A0) Sources of information
  36. A1) What is it?
  37. A2) What is good at?
  38. A3) On what machines will it run?  (Plus important compilation notes)
  39. A4) What's the latest version?
  40. A5) Where do I get it?
  41. A6) I don't have root access: how do I make zsh my login shell?
  42.  
  43. Section B:  How does zsh differ from...?
  44. B1) sh and ksh?
  45. B2) csh?
  46. B3) Why do my csh aliases not work?  (Plus other alias pitfalls.)
  47. B4) tcsh?
  48. B5) bash?
  49. B6) Shouldn't zsh be more/less like ksh/(t)csh?
  50.  
  51. Section C:  How to get various things to work
  52. C1) How do I turn off spelling correction/globbing for an individual command?
  53. C2) How do I get the meta key to work on my xterm?
  54. C3) Why does my terminal act funny in some way?
  55. C4) Why does `$var' where var="foo bar" not do what I expect?
  56. C5) Why do my autoloaded functions not autoload [the first time]?
  57. C6) How does base arithmetic work?
  58. C7) How do I get a newline in my prompt?
  59. C8) Why does `bindkey ^a command-name' or 'stty intr ^-' do something funny?
  60. C9) Why can't I bind \C-s and \C-q any more?
  61. C10) How do I execute command `foo' within function `foo'?
  62. C11) Why do history substitutions with single bangs do something funny?
  63. C12) Why does zsh kill off all my background jobs when I logout?
  64. C13) How do I list all my history entries?
  65.  
  66. Section D:  The mysteries of completion
  67. D1) What is completion?
  68. D2) What sorts of things can be completed?
  69. D3) How does zsh deal with ambiguous completions?
  70. D4) How do I get started with programmable completion?
  71. D5) And if programmable completion isn't good enough?
  72.  
  73. Section Z:  The future of zsh
  74. Z1) What bugs are currently known and unfixed? (Plus recent important changes)
  75. Z2) Where do I report bugs, get more info / who's working on zsh?
  76. Z3) What's on the wish-list?
  77.  
  78. Acknowledgments
  79.  
  80. Copyright
  81. --- End of Contents ---
  82.  
  83.  
  84. Section A:  Introducing zsh and how to install it
  85.  
  86. A0) Sources of information
  87.  
  88.   Information on zsh is now available via the World Wide Web.  The URL
  89.   is "http://www.mal.com/zsh/".  The server provides this FAQ and much
  90.   else (thanks to Mark Borges for this).  The FAQ is at
  91.   "http://www.mal.com/zsh/FAQ/".
  92.  
  93.   Another useful source of information is the collection of FAQ articles
  94.   posted frequently to the Usenet news groups comp.unix.questions,
  95.   comp.unix.shells and comp.answers with answers to general questions
  96.   about UNIX.  The fifth of the seven articles deals with shells,
  97.   including zsh, with a brief description of differences.  (This article
  98.   also talks about shell startup files which would otherwise rate a
  99.   mention here.)  There is also a separate FAQ on shell differences
  100.   and how to change your shell.  Usenet FAQs are available via FTP
  101.   from rtfm.mit.edu and mirrors and also on the World Wide Web; see
  102.     USA         http://www.cis.ohio-state.edu/hypertext/faq/usenet/top.html
  103.     UK          http://www.lib.ox.ac.uk/internet/news/faq/comp.unix.shell.html
  104.     Netherlands http://www.cs.ruu.nl/wais/html/na-dir/unix-faq/shell/.html
  105.  
  106.   The latest version of this FAQ is also available directly from any
  107.   of the zsh archive sites listed in question A5).
  108.  
  109.   Note that if you are reading this file with GNU Emacs 19 and have my
  110.   cross-referencing package xref.el (soon to be part of Emacs, but
  111.   currently available from
  112.   http://python.swan.ac.uk/~pypeters/comp/xref.html), you can pick up
  113.   a version of this FAQ which is internally cross-referenced from:
  114.   http://python.swan.ac.uk/~pypeters/comp/zsh.FAQ
  115.  
  116.   (As a lower-tech method of reading this in Emacs, you can type
  117.   \M-2 \C-x $ to make all the indented text vanish, then \M-0 \C-x $
  118.   when you are on the title you want.)
  119.  
  120.   For any more eclectic information, you should contact the mailing
  121.   list:  see question Z2).
  122.  
  123.  
  124. A1) What is it?
  125.  
  126.   Zsh is a UNIX command interpreter (shell) which of the standard shells
  127.   most resembles the Korn shell (ksh), although it is not completely
  128.   compatible.  It includes enhancements of many types, notably in the
  129.   command-line editor, options for customising its behaviour, filename
  130.   globbing, features to make C-shell (csh) users feel more at home and
  131.   extra features drawn from tcsh (another `custom' shell).
  132.  
  133.   It was written by Paul Falstad when a student at Princeton; however,
  134.   Paul doesn't maintain it any more and enquiries should be sent to
  135.   the mailing list (see question Z2).  Zsh is distributed under a
  136.   standard Berkeley style copyright.
  137.  
  138.   For more information, the files Doc/intro.txt or Doc/intro.troff
  139.   included with the source distribution are highly recommended.  A list
  140.   of features is given in FEATURES, also with the source.
  141.  
  142.  
  143. A2) What is it good at?
  144.  
  145.   Here are some things that zsh is particularly good at.  No claim of
  146.   exclusivity is made, especially as shells copy one another, though
  147.   in the areas of command line editing and globbing zsh is well ahead
  148.   of the competition.  I am not aware of a major feature in any other
  149.   freely-available shell which zsh does not also have (except smallness).
  150.  
  151.   Command line editing:
  152.     programmable completion: incorporates the ability to use
  153.       the full power of zsh globbing (compctl -g),
  154.     multi-line commands editable as a single buffer (even files!),
  155.     variable editing (vared),
  156.     command buffer stack,
  157.     print text straight into the buffer for immediate editing (print -z),
  158.     execution of unbound commands,
  159.     menu completion,
  160.     variable, editing function and option name completion,
  161.     inline expansion of variables, history commands.
  162.   Globbing --- extremely powerful, including:
  163.     recursive globbing (cf. find),
  164.     file attribute qualifiers (size, type, etc. also cf. find),
  165.     full alternation and negation of patterns.
  166.   Handling of multiple redirections (simpler than tee).
  167.   Large number of options for tailoring.
  168.   Path expansion (=foo -> /usr/bin/foo).
  169.   Adaptable messages for spelling, watch, time as well as prompt
  170.     (including conditional expressions).
  171.   Named directories.
  172.   Comprehensive integer arithmetic.
  173.   Manipulation of arrays (including reverse subscripting).
  174.   Spelling correction.
  175.  
  176.  
  177. A3) On what machines will it run?
  178.  
  179.   Zsh was written for machines of the Berkeley UNIX family; most such
  180.   machines (and all the most popular) will run it without major
  181.   surgery.  Modifications have been made so that it works under
  182.   SYSVR4-based operating systems such as Solaris 2.x and OSF/1.  The
  183.   best thing is to suck it and see.  Success has been obtained on
  184.   older SYSVR3 systems, but you may need to modify the code.
  185.  
  186.   From version 2.6, the installation mechanism has been altered to use
  187.   GNU Autoconf, which should make it easier to recognise new machine
  188.   types.  If you need to change something to support a new machine, it
  189.   would be appreciated if you could add any necessary preprocessor
  190.   code and alter configure.in to configure zsh automatically, then
  191.   send the required context diffs to the list (see question Z2).
  192.  
  193.   To get it to work, retrieve the source distribution (see question
  194.   A5), un-gzip it, un-tar it and read the INSTALL file in the top
  195.   directory.  Here are a couple of known installation problems at
  196.   present.
  197.  
  198.   *Note for Solaris 2.2 and 2.3*: The UCB versions of the routines for
  199.   reading directories are not usable (the struct definitions are
  200.   incompatible with the ones assumed by zsh).  The symptom of this is
  201.   that globbed filenames in the compiled version of zsh will be
  202.   missing the first two letters.  To avoid this, make sure you compile
  203.   zsh without any reference to /usr/ucblib in (e.g.) your
  204.   LD_LIBRARY_PATH.
  205.  
  206.   *Note for OSF/1 3.0*: There is apparently a bug in the header file
  207.   /usr/include/rpcsvc/ypclnt.h; the prototype for yp_all() has a
  208.   struct ypall_callback as its final argument, which should be a
  209.   pointer (struct ypall_callback *).  This prevents compilation of
  210.   zle_tricky.c.  If you can't modify the header file, make a
  211.   subdirectory called rpcsvc, copy ypclnt.h there, modify that copy,
  212.   and put a `-I.' argument into CFLAGS in Makefile for the Src
  213.   subdirectory when compiling.
  214.  
  215.   *Note for users of nawk* (The following information comes from
  216.   Zoltan Hidvegi):  On some systems nawk is broken and produces an
  217.   incorrect signames.h file. This make the signals code unusable. This
  218.   often happens on Ultrix, HP-UX, IRIX (?). Install gawk if you
  219.   experience such problems.
  220.  
  221.  
  222. A4) What's the latest version?
  223.  
  224.   Zsh 2.5.0 was the last major release:  the final form is 2.5.03.
  225.   Many bugs were fixed after 2.3.1, which was the previous major
  226.   release, and there were many new features, notably programmable
  227.   completion.  This version is known to have a bug with pipelines
  228.   inside other shell structures (now fixed in 2.6).
  229.  
  230.   Work has now started on 2.6 and 2.6-beta22 is available; note that
  231.   even numbered minor versions are not released.  Development of zsh
  232.   is usually patch by patch, with each intermediate version publicly
  233.   available.  Note that this `open' development system does mean bugs
  234.   are sometimes introduced into the most recent archived version.
  235.   These are usually fixed quickly.  Note also that as the shell
  236.   changes, it may become incompatible with older versions; see the
  237.   end of question Z1 for a partial list.  Changes of this kind are
  238.   almost always forced by an awkward or unnecessary feature in the
  239.   original design (as perceived by current users), or to enhance
  240.   compatibility with other Bourne shell derivatives.
  241.  
  242.  
  243. A5) Where do I get it?
  244.  
  245.   The archive is now run by Zoltan Hidvegi <hzoli@cs.elte.hu>.
  246.   The following are known mirrors (kept frequently up to date); the
  247.   first is the official archive site.  All are available by anonymous
  248.   FTP.
  249.  
  250.     Hungary     ftp://ftp.cs.elte.hu/pub/zsh/
  251.     Australia   ftp://ftp.ips.oz.au/pub/packages/zsh/
  252.     France      ftp://ftp.cenatls.cena.dgac.fr/pub/shells/zsh/
  253.     Germany     ftp://ftp.fu-berlin.de/pub/unix/shells/zsh/
  254.                 ftp://ftp.uni-trier.de/pub/unix/shell/zsh/
  255.                 ftp://ftp.prz.tu-berlin.de/pub/unix/shells/zsh
  256.     Japan       ftp://ftp.tohoku.ac.jp/mirror/zsh/
  257.                 ftp://ftp.iij.ad.jp/pub/misc/zsh/
  258.     Norway      ftp://ftp.uit.no/pub/unix/shells/zsh/
  259.     Sweden      ftp://ftp.lysator.liu.se/pub/unix/zsh/
  260.     UK          ftp://ftp.net.lut.ac.uk/zsh/
  261.                 (also by FSP at port 21)
  262.     USA         ftp://ftp.math.gatech.edu/pub/zsh/
  263.                 ftp://uiarchive.cso.uiuc.edu/pub/packages/shells/zsh/
  264.                 ftp://ftp.sterling.com/zsh/
  265.                 ftp://ftp.rge.com/pub/shells/zsh/
  266.  
  267.   (If you don't understand URL's, the first thing after the ftp:// is
  268.   the hostname and the remainder after the / is the directory.  You
  269.   can supply these directly to a Web browser.  If you're reading this
  270.   with a recent version of Netscape Navigator, you may just have to
  271.   click on them.)
  272.  
  273.   The latest full release is in zsh.tar.gz in these directories.  Note
  274.   that this is in gzip format: you will need GNU gzip from your
  275.   nearest GNU archive to unpack it.  The up-to-the-minute development
  276.   version is in zsh-beta.tar.gz.  There is also a version under RCS
  277.   control which may be more suitable for source hackers.
  278.  
  279.  
  280. A6) I don't have root access: how do I make zsh my login shell?
  281.  
  282.   Unfortunately, on many machines you can't use `chsh' to change your
  283.   shell unless the name of the shell is contained in /etc/shells, so if
  284.   you have your own copy of zsh you need some sleight-of-hand to use it
  285.   when you log on.  (Simply typing `zsh' is not really a solution since
  286.   you still have your original login shell waiting for when you exit.)
  287.  
  288.   The basic idea is to use `exec <zsh-path>' to replace the current
  289.   shell with zsh.  Often you can do this in a login file such as
  290.   .profile (if your shell is sh or ksh) or .login (if it's csh).  Make
  291.   sure you have some way of altering the file (e.g. via FTP) before you
  292.   try this as `exec' is often rather unforgiving.
  293.  
  294.   If you have zsh in a subdirectory `bin' of your home directory,
  295.   put this in .profile:
  296.         [ -f $HOME/bin/zsh ] && exec $HOME/bin/zsh -l
  297.   or if your login shell is csh or tcsh, put this in .login:
  298.         if ( -f ~/bin/zsh ) exec ~/bin/zsh -l
  299.   (in each case the -l tells zsh it is a login shell).
  300.  
  301.   If you want to check this works before committing yourself to it,
  302.   you can make the login shell ask whether to exec zsh.  The following
  303.   work for Bourne-like shells:
  304.         [ -f $HOME/bin/zsh ] && {
  305.                 echo "Type Y to run zsh: \c"
  306.                 read line
  307.                 [ "$line" = Y ] && exec $HOME/bin/zsh -l
  308.         }
  309.   and for C-shell-like shells:
  310.         if ( -f ~/bin/zsh ) then
  311.                 echo -n "Type Y to run zsh: "
  312.                 if ( "$<" == Y ) exec ~/bin/zsh -l
  313.         endif
  314.  
  315.  
  316.   It's not a good idea to put this (even without the -l) into .cshrc,
  317.   at least without some tests on what the csh is supposed to be doing,
  318.   as that will cause _every_ instance of csh to turn into a zsh and
  319.   will cause csh scripts (yes, unfortunately some people write these)
  320.   which do not call `csh -f' to fail.  If you want to tell xterm to
  321.   run zsh, change the SHELL environment variable to the full path of
  322.   zsh at the same time as you exec zsh (in fact, this is sensible for
  323.   consistency even if you aren't using xterm).  If you have to exec
  324.   zsh from your .cshrc, a minimum safety check is `if ($?prompt) exec
  325.   zsh'.
  326.  
  327.   If you like your login shell to appear in the process list as '-zsh',
  328.   you can link zsh to -zsh (e.g. by `ln -s ~/bin/zsh ~/bin/-zsh') and
  329.   change the exec to `exec -zsh'.  (Make sure -zsh is in your path.)
  330.   This has the same effect as the `-l' option.
  331.  
  332.   Footnote: if you DO have root access, make sure zsh goes in
  333.   /etc/shells on all appropriate machines, including NIS clients, or you
  334.   may have problems with FTP to that machine.
  335.  
  336.  
  337. Section B:  How does zsh differ from...?
  338.  
  339. As has already been mentioned, zsh is most similar to ksh, while many
  340. of the additions are to please csh users.  Here are some more detailed
  341. notes.
  342.  
  343. B1) Differences from sh and ksh
  344.  
  345.   Most features of ksh (and hence also of sh) are implemented in zsh;
  346.   problems can arise because the implementation is slightly different.
  347.   Note also that not all ksh's are the same either.  I have based this
  348.   on the 11/16/88f version of ksh.
  349.  
  350.   The classic difference is word splitting, discussed in C4); this
  351.   catches out very many beginning zsh users.  As explained there, this
  352.   is actually a bug in every other shell.  The answer is to set
  353.   SH_WORD_SPLIT for backward compatibility.  The next most classic
  354.   difference is that unmatched glob patterns cause the command to
  355.   abort; set NO_NOMATCH for those.
  356.   
  357.   Here is a list of various options which will increase ksh
  358.   compatibility, though maybe decrease zsh's abilities: see the manual
  359.   entries for GLOB_SUBST, IGNORE_BRACES (though brace expansion occurs
  360.   in some versions of ksh), KSH_ARRAYS, KSH_OPTION_PRINT, LOCAL_OPTIONS,
  361.   NO_BAD_PATTERN, NO_BANG_HIST, NO_EQUALS, NO_HUP, NO_NOMATCH, NO_RCS,
  362.   NO_SHORT_LOOPS, PROMPT_SUBST, RM_STAR_SILENT, SH_GLOB, SH_WORD_SPLIT
  363.   (see question C4) and SINGLE_LINE_ZLE.  Note that you can also
  364.   disable any built-in commands which get in your way.  If invoked as
  365.   `ksh', the shell will try and set suitable options.
  366.  
  367.   Here are some differences from ksh which might prove significant for
  368.   ksh programmers, some of which may be interpreted as bugs; there must
  369.   be more.  Note that this list is deliberately rather full and that
  370.   most of the items are fairly minor.  Those marked `*' perform in a
  371.   ksh-like manner if the shell is invoked with the name `ksh'; those
  372.   marked - have recently (i.e., between the release and the beta
  373.   version) become ksh-compatible.  Capitalised words with underlines
  374.   refer to shell options. 
  375.  
  376.   Syntax:
  377.   * Shell word splitting: see question C4).
  378.   * Arrays are (by default) more csh-like than ksh-like:
  379.       subscripts start at 1, not 0; array[0] refers to array[1];
  380.       `$array' refers to the whole array, not $array[0];
  381.       braces are unnecessary: $a[1] == ${a[1]}, etc.
  382.       The KSH_ARRAYS option is available from version 2.6-beta17; note
  383.       even in this case $array[2] with no braces refers to element 2
  384.       of $array, etc.
  385.     Coprocesses are established by `coproc'; `|&' behaves like csh.
  386.   - Opening for both input and output via <> is only available from
  387.       2.6-beta21; before it performed globbing of any sequence of
  388.       decimal digits.  For the latter, you now need <->.
  389.   Command line substitutions, globbing etc.:
  390.   * Failure to match a globbing pattern causes an error (use
  391.       NO_NOMATCH).
  392.   * The results of parameter substitutions are treated as plain text:
  393.       `foo="*"; print $foo' prints all files in ksh but * in zsh.
  394.       (GLOB_SUBST has just been added to fix this.)
  395.   - On the other hand, `foo=*' does globbing immediately on the right
  396.       hand side of the assignment (this has changed from 2.6-beta17;
  397.       the old behaviour now requires the option GLOB_ASSIGN).
  398.     The backslash in $(echo '\$x') is treated differently:  in ksh, it
  399.       is not stripped, in zsh it is.  (The `...` form gives the same in
  400.       both shells.)
  401.   * $PSn do not do parameter substitution by default (use PROMPT_SUBST).
  402.     Globbing does not allow ksh-style `pattern-lists'.  Equivalents:
  403.       -------------------------------------------------------------------
  404.              ksh             zsh          Meaning
  405.             -----           -----        ---------
  406.            !(foo)            ^foo        Anything but foo.
  407.                       or   foo1~foo2     Anything matching foo1 but foo2[1].
  408.       @(foo1|foo2|...)  (foo1|foo2|...)  One of foo1 or foo2 or ...
  409.            ?(foo)           (foo|)       Zero or one occurrences of foo.
  410.            *(foo)           (foo)#       Zero or more occurrences of foo.
  411.            +(foo)           (foo)##      One or more occurrences of foo.
  412.       -------------------------------------------------------------------
  413.       The `^', `~' and `#' (but not `|')forms require EXTENDED_GLOB.
  414.       [1] Note that ~ is the only globbing operator to have a lower
  415.         precedence than `/'.  For example, `**/foo~*bar*' matches any
  416.         file in a subdirectory called `foo', except where `bar'
  417.         occurred somewhere in the path (e.g. `users/barstaff/foo' will
  418.         be excluded by the ~ operator).  As the `**' operator cannot
  419.         be grouped (inside parentheses it is treated as *), this is
  420.         the way to exclude some subdirectories from matching a `**'.
  421.     Unquoted assignments do file expansion after `:'s (intended for PATHs).
  422.     `integer' does not allow -i.
  423.   Command execution:
  424.   * There is no $ENV variable (use /etc/zshrc, ~/.zshrc; note also $ZDOTDIR).
  425.     $PATH is not searched for commands specified at invocation without -c.
  426.   Aliases and functions:
  427.     The order in which aliases and functions are defined is significant
  428.       (function definitions with () expand aliases -- see question B3).
  429.     Aliases and functions cannot be exported.
  430.     There are no tracked aliases: command hashing replaces these.
  431.     The use of aliases for key bindings is replaced by `bindkey'.
  432.   * Options are not local to functions (use LOCAL_OPTIONS; note this
  433.       may always be unset locally to propagate options settings from a
  434.       function to the calling level). 
  435.   Traps and signals:
  436.     Traps are not local to functions, are not reset automatically when
  437.       called, and are called as functions themselves (this is a bug
  438.       for the `trap "..." NAL' form of trap setting). 
  439.     TRAPERR has become TRAPZERR (this was forced by UNICOS which has SIGERR).
  440.   Editing:
  441.     The options emacs, gmacs, trackall, viraw are not supported.
  442.       Use bindkey to change the editing behaviour: `set -o {emacs,vi}'
  443.       become `bindkey -{e,v}'; for gmacs, go to emacs mode and use
  444.       `bindkey \^t gosmacs-transpose-characters'.  `Trackall' is replaced
  445.       by `hashcmds'.
  446.     The `keyword' option does not exist and -k is instead interactivecomments.
  447.       (`keyword' will not be in the next ksh release either.)
  448.     Management of histories in multiple shells is different:
  449.       the history list is not saved and restored after each command.
  450.     \ does not escape editing chars (use ^V).
  451.     Not all ksh bindings are set (e.g. `<ESC>#'; try <ESC>q).
  452.   * # in an interactive shell is not treated as a comment by default.
  453.   Built-in commands:
  454.     Some built-ins (r, autoload, history, integer ...) were aliases in ksh.
  455.     There is no built-in command newgrp: use e.g. `alias newgrp="exec newgrp"'
  456.     `jobs' has no `-n' flag.
  457.     `read' has no `-s' flag.
  458.     In `let "i = foo"', foo is evaluated as a number, not an expression
  459.       (although in `let "i = $foo"' it is treated as an expression).
  460.   Other idiosyncrasies:
  461.     `select' always redisplays the list of selections on each loop.
  462.  
  463.  
  464. B2) Similarities with csh
  465.  
  466.   Although certain features aim to ease the withdrawal symptoms of csh
  467.   (ab)users, the syntax is in general rather different and you should
  468.   certainly not try to run scripts without modification.  The c2z script
  469.   is provided with the source (in scripts/c2z) to help convert .cshrc
  470.   and .login files; see also the next question concerning aliases,
  471.   particularly those with arguments.
  472.  
  473.   Csh-compatibility additions include:
  474.     Logout, rehash, source, (un)limit built-in commands.
  475.     *rc file for interactive shells.
  476.     Directory stacks.
  477.     Cshjunkie*, ignoreeof options.
  478.     The CSH_NULL_GLOB option.
  479.     >&, |& etc. redirection.
  480.       (Note that `>file 2>&1' is the standard Bourne shell command for
  481.       csh's `>&file'.)
  482.     foreach ... loops; alternative syntax for other loops.
  483.     Alternative syntax `if ( ... ) ...' (also `for', `which'; this now
  484.       requires the CSH_JUNKIE_PAREN option).
  485.     $PROMPT as well as $PS1, $status as well as $?, $#argv as well as $#, ....
  486.     Escape sequences via % for prompts.
  487.     Special array variables $PATH etc. are colon-separated, $path are arrays.
  488.     !-type history (which may be turned off via `setopt nobanghist').
  489.     Arrays have csh-like features (see under B1)).
  490.  
  491.  
  492. B3) Why do my csh aliases not work?  (Plus other alias pitfalls.)
  493.  
  494.   First of all, check you are using the syntax
  495.         alias newcmd='list of commands'
  496.   and not
  497.         alias newcmd 'list of commands'
  498.   which won't work. (It tells you if `newcmd' and `list of commands' are
  499.   already defined as aliases.)
  500.  
  501.   Otherwise, your aliases probably contain references to the command
  502.   line of the form `\!*', etc.  Zsh does not handle this behaviour as it
  503.   has shell functions which provide a way of solving this problem more
  504.   consistent with other forms of argument handling.  For example, the
  505.   csh alias
  506.         alias cd 'cd \!*; echo $cwd'
  507.   can be replaced by the zsh function,
  508.         cd() { builtin cd $*; echo $PWD; }
  509.   (the `builtin' tells zsh to use its own `cd', avoiding an infinite loop)
  510.   or, perhaps better,
  511.         cd() { builtin cd $*; print -D $PWD; }
  512.   (which converts your home directory to a ~).  In fact, this problem is
  513.   better solved by defining the special function chpwd() (see the manual).
  514.   Note also that the `;' at the end of the function is optional in zsh,
  515.   but not in ksh or sh (for sh's where it exists).
  516.  
  517.   Here is Bart Schaefer's guide to converting csh aliases for zsh.
  518.  
  519.     1.  If the csh alias references "parameters" (\!:1 \!* etc.),
  520.         then in zsh you need a function (referencing $1 $* etc.).
  521.         Otherwise, you can use a zsh alias.
  522.  
  523.     2.  If you use a zsh function, you need to refer _at_least_ to
  524.         $* in the body (inside the { }).  Parameters don't magically
  525.         appear inside the { } the way they get appended to an alias.
  526.  
  527.     3.  If the csh alias references its own name (alias rm "rm -i"),
  528.         then in a zsh function you need the "command" keyword
  529.         (function rm() { command rm -i $* }), but in a zsh alias
  530.         you don't (alias rm="rm -i").
  531.  
  532.     4.  If you have aliases that refer to each other (alias ls "ls -C";
  533.         alias lf "ls -F" ==> lf == ls -C -F) then you must either:
  534.         a.  convert all of them to zsh functions; or
  535.         b.  after converting, be sure your .zshrc defines all of your
  536.             aliases before it defines any of your functions.
  537.  
  538.     Those first four are all you really need, but here are four more for
  539.     heavy csh alias junkies:
  540.  
  541.     5.  Mapping from csh alias "parameter referencing" into zsh function
  542.         (assuming shwordsplit and ksharrays are NOT set in zsh):
  543.              csh                   zsh
  544.             =====               ==========
  545.             \!*                 $*              (or $argv)
  546.             \!^                 $1              (or $argv[1])
  547.             \!:1                $1
  548.             \!:2                $2              (or $argv[2], etc.)
  549.             \!$                 $*[$#]          (or $argv[$#], or $*[-1])
  550.             \!:1-4              $*[1,4]
  551.             \!:1-               $*[1,$#-1]      (or $*[1,-2])
  552.             \!^-                $*[1,$#-1]
  553.             \!*:q               "$@"            ($*:q doesn't work (yet))
  554.             \!*:x               $=*             ($*:x doesn't work (yet))
  555.  
  556.     6.  Remember that it is NOT a syntax error in a zsh function to
  557.         refer to a position ($1, $2, etc.) greater than the number of
  558.         parameters. (E.g., in a csh alias, a reference to \!:5 will
  559.         cause an error if 4 or fewer arguments are given; in a zsh
  560.         function, $5 is the empty string if there are 4 or fewer
  561.         parameters.)
  562.  
  563.     7.  To begin a zsh alias with a - (dash, hyphen) character, use
  564.         "alias --":
  565.                  csh                            zsh
  566.             ===============             ==================
  567.             alias - "fg %-"             alias -- -="fg %-"
  568.  
  569.     8.  Stay away from "alias -g" in zsh until you REALLY know what
  570.         you're doing.
  571.  
  572.   There is one other serious problem with aliases: consider
  573.         alias l='/bin/ls -F'
  574.         l() { /bin/ls -la $* | more }
  575.   `l' in the function definition is in command position and is expanded
  576.   as an alias, defining `/bin/ls' and `-F' as functions which call
  577.   `/bin/ls', which gets a bit recursive.  This can be avoided if you use
  578.   `function' to define a function, which doesn't expand aliases.  It is
  579.   possible to argue for extra warnings somewhere in this mess.  Luckily,
  580.   it is not possible to define `function' as an alias.
  581.  
  582.  
  583. B4) Similarities with tcsh:
  584.  
  585.   (The sections on csh apply too, of course.)  Certain features have
  586.   been borrowed from tcsh, including $watch, run-help, $savehist,
  587.   $histlit, periodic commands etc., extended prompts, sched and which
  588.   built-ins.  Programmable completion was inspired by, but is entirely
  589.   different to, tcsh's `complete'.  (There is a perl script called
  590.   lete2ctl in the scripts directory of the source distribution to
  591.   convert `complete' to `compctl' statements.)  This list is not
  592.   definitive: some features have gone in the other direction.
  593.  
  594.   If you're missing the editor function run-fg-editor, try something
  595.   with bindkey -s (which binds a string to a keystroke), e.g.
  596.         bindkey -s '^z' '\eqfg %$EDITOR:t\n'
  597.   which pushes the current line onto the stack and tries to bring a job
  598.   with the basename of your editor into the foreground.  Bindkey -s
  599.   allows limitless possibilities along these lines.
  600.  
  601.  
  602. B5) Similarities with bash
  603.  
  604.   Zsh has almost all the features that bash has (and much more); in
  605.   addition it is about twice as fast, though this is less impressive
  606.   than it sounds.  With the new malloc by Sven Wischnowsky (only used
  607.   if you used `configure --enable-zsh-mem' when configuring), zsh uses
  608.   about the same amount of heap memory as bash, which was previously
  609.   the biggest gripe.  The only feature I am aware of that zsh doesn't
  610.   have is setting a numerical value for ignoreeof --- it's always 10
  611.   --- but of course I don't use bash :-).
  612.  
  613.   On the other hand, zsh has no claims towards Posix compliancy and will
  614.   not use GNU readline (zle is more powerful).  In fact, bash is
  615.   intended more as an enhanced sh than a ksh work-alike; it doesn't
  616.   handle [[ ... ]], or (yet) arrays, for example.  Of course, they're
  617.   working on bash, too.  Some zsh-like features are suggested for
  618.   future versions.
  619.  
  620.  
  621. B6) Shouldn't zsh be more/less like ksh/(t)csh?
  622.  
  623.   People often ask why zsh has all these `unnecessary' csh-like features,
  624.   or alternatively why zsh doesn't understand more csh syntax.  This is
  625.   far from a definitive answer and the debate will no doubt continue.
  626.  
  627.   Paul's object in writing zsh was to produce a ksh-like shell which
  628.   would have features familiar to csh users.  For a long time, csh was
  629.   the preferred interactive shell and there is a strong resistance to
  630.   changing to something unfamiliar, hence the additional syntax and
  631.   CSH_JUNKIE options.  This argument still holds.  On the other hand,
  632.   the arguments for having what is close to a plug-in replacement for ksh
  633.   are, if anything, even more powerful:  the deficiencies of csh as a
  634.   programming language are well known (look in any Usenet FAQ archive, e.g.
  635.     http://www.cis.ohio-state.edu/hypertext/faq/usenet/unix-faq/shell/\
  636.     csh-whynot/faq.html
  637.   if you are in any doubt) and zsh is able to run many standard
  638.   scripts such as /etc/rc.
  639.  
  640.   Of course, this makes zsh rather large and feature-ridden so that it
  641.   seems to appeal mainly to hackers --- but note it is only slightly
  642.   larger than bash and tcsh, and uses much less memory and CPU time
  643.   than tcsh.  The only answer, perhaps not entirely satisfactory, is
  644.   that you have to ignore the bits you don't want.
  645.  
  646.  
  647. Section C:  How to get various things to work
  648.  
  649. C1) How do I turn off spelling correction/globbing for an individual command?
  650.  
  651.   In the first case, you presumably have `setopt correctall' in an
  652.   initialisation file, so that zsh checks the spelling of each word in
  653.   the command line.  You probably do not want this behaviour for
  654.   commands which do not operate on existing files.
  655.  
  656.   The answer is to alias the offending command to itself with
  657.   `nocorrect' stuck on the front, e.g.
  658.        alias mkdir='nocorrect mkdir'
  659.  
  660.   To turn off globbing, the rationale is identical:
  661.        alias mkdir='noglob mkdir'
  662.   (you can have both nocorrect and nglob, if you like).
  663.  
  664.  
  665. C2) How do I get the meta key to work on my xterm?
  666.  
  667.   As stated in the manual, zsh needs to be told about the meta key by
  668.   using `bindkey -me' or `bindkey -mv' in your .zshrc or on the command
  669.   line.  You probably also need to tell the terminal driver to allow the
  670.   `meta' bit of the character through; `stty pass8' is the usual
  671.   incantation.  Sample .zshrc entry:
  672.         [[ $TERM = "xterm" ]] && stty pass8 && bindkey -me
  673.   or, on SYSVR4-ish systems without pass8,
  674.         [[ $TERM = "xterm" ]] && stty -parenb -istrip cs8 && bindkey -me
  675.   (disable parity detection, don't strip high bit, use 8-bit characters).
  676.   Make sure this comes *before* any bindkey entries in your .zshrc which
  677.   redefine keys normally defined in the emacs/vi keymap.
  678.  
  679.  
  680. C3) Why does my terminal act funny in some way?
  681.  
  682.   If you are using an OpenWindows cmdtool as your terminal, any
  683.   escape sequences (such as those produced by cursor keys) will be
  684.   swallowed up and never reach zsh.  Either use shelltool or avoid
  685.   commands with escape sequences.  You can also disable scrolling from
  686.   the cmdtool pane menu (which effectively turns it into a shelltool).
  687.   If you still want scrolling, try using an xterm with the scrollbar
  688.   activated.
  689.  
  690.   If that's not the problem, and you are using stty to change some tty
  691.   settings, make sure you haven't asked zsh to freeze the tty settings:
  692.   type
  693.         ttyctl -u
  694.   before any stty commands you use.
  695.  
  696.   On the other hand, if you aren't using stty and have problems you may
  697.   need the opposite:  `ttyctl -f' freezes the terminal to protect it
  698.   from hiccups introduced by other programmes (kermit has been known to
  699.   do this).
  700.  
  701.   If _that's_ not the problem, and you are having difficulties with
  702.   external commands (not part of zsh), and you think some terminal
  703.   setting is wrong (e.g. ^V is getting interpreted as `literal next
  704.   character' when you don't want it to be), try
  705.         ttyctl -u
  706.         STTY='lnext "^-"' commandname
  707.   (in this example), or just export STTY for all commands to see.  Note
  708.   that zsh doesn't reset the terminal completely afterwards: just the
  709.   modes it uses itself and a number of special processing characters
  710.   (see the stty(1) manual page).
  711.  
  712.   At some point there may be an overhaul which allows the terminal
  713.   modes used by the shell to be modified separately from those seen by
  714.   external programmes.  This is partially implemented already: in 2.5,
  715.   the shell is less susceptible to mode changes inherited from
  716.   programmes than it used to be.
  717.  
  718.  
  719. C4) Why does `$var' where var="foo bar" not do what I expect?
  720.  
  721.   In most Bourne-shell derivatives, multiple-word variables such as
  722.         var="foo bar"
  723.   are split into words when passed to a command or used in a `for foo in
  724.   $var' loop.  By default, zsh does not have that behaviour: the
  725.   variable remains intact.  (This is not a bug!  See below.)  An option
  726.   (shwordsplit) exists to provide compatibility.
  727.  
  728.   For example, defining the function args to show the number of its
  729.   arguments:
  730.         args() { echo $#; }
  731.   and with our definition of `var',
  732.         args $var
  733.   produces the output `1'.  After
  734.         setopt shwordsplit
  735.   the same function produces the output `2', as with sh and ksh.
  736.  
  737.   Unless you need strict sh/ksh compatibility, you should ask yourself
  738.   whether you really want this behaviour, as it can produce unexpected
  739.   effects for variables with entirely innocuous embedded spaces.  This
  740.   can cause horrendous quoting problems when invoking scripts from
  741.   other shells.  The natural way to produce word-splitting behaviour
  742.   in zsh is via arrays.  For example,
  743.         set -A array one two three twenty
  744.   (or
  745.         array=(one two three twenty)
  746.   if you prefer), followed by
  747.         args $array
  748.   produces the output `4', regardless of the setting of shwordsplit.
  749.   Arrays are also much more versatile than single strings.  Probably
  750.   if this mechanism had always been available there would never have
  751.   been automatic word splitting in scalars, which is a sort of
  752.   uncontrollable poor man's array.
  753.  
  754.   Note that this happens regardless of the value of the internal field
  755.   separator, $IFS; in other words, with `IFS=:; foo=a:b; args $foo' you
  756.   get the answer 1.
  757.  
  758.   Other ways of causing word splitting include a judicious use of
  759.   `eval':
  760.         sentence="Longtemps, je me suis couch\\'e de bonne heure."
  761.         eval "words=(\"$sentence\")"
  762.   after which $words is an array with the words of $sentence, or, less
  763.   standard but more reliable, turning on shwordsplit for one variable
  764.   only:
  765.         args ${=sentence}
  766.   always returns 8 with the above definition of `args'.  (In older
  767.   versions of zsh, ${=foo} toggled shwordsplit; now it forces it on.)
  768.  
  769.   Note also the "$@" method of word splitting is always available in zsh
  770.   functions and scripts (though strictly this does array splitting, not
  771.   word splitting).
  772.  
  773.   Shwordsplit is set when zsh is invoked with the names `ksh' or `sh'.
  774.  
  775.  
  776. C5) Why do my autoloaded functions not autoload [the first time]?
  777.  
  778.   When you put a shell function in an autoload directory (i.e. one
  779.   mentioned in $FPATH), it should be written just as if it were a
  780.   shell script.  In other words, there should be no line at the
  781.   beginning saying `function foo {' or `foo () {', and consequently no
  782.   matching '}' at the end.  If you include those, then the first time
  783.   you try to use the function, the _whole_ file is run --- in other
  784.   words, zsh simply defines the function and does nothing else.
  785.  
  786.   As a concrete example, if you have a function which you would define
  787.   on the command line as `xhead () { print -n "\033]2;$*\a"; }' and
  788.   your have assigned `FPATH=~/fns', then your .zshrc should contain
  789.   `autoload xhead' and the file ~/fns/xhead should contain only
  790.   `print -n "\033]2;$*\a"'.  (A neat trick to autoload all functions
  791.   in a given directory is to include a line like `autoload ~/fns/*(:t)'
  792.   in .zshrc; the bit in parentheses removes the directory part of the
  793.   filenames, leaving just the function names.)
  794.  
  795.   The shell has just (version 2.6 beta 5) been enhanced to allow the
  796.   Korn shell syntax, where the file contains the whole function
  797.   including the definition lines.  However, the form given above is
  798.   unlikely to disappear as it allows significant benefits, including
  799.   using a function directly as a script, and being able to link a
  800.   function under different names.
  801.  
  802.  
  803. C6) How does base arithmetic work?
  804.  
  805.   The ksh syntax is now understood, i.e.
  806.         let 'foo = 16#ff'
  807.   or equivalently
  808.         (( foo = 16#ff ))
  809.   or even
  810.         foo=$[16#ff]
  811.   (note that `foo=$((16#ff))' is supported from version 2.6 onward).
  812.   The original syntax was
  813.         (( foo = [16]ff ))
  814.   --- this was based on a misunderstanding of the ksh manual page.  It
  815.   still works but its use is deprecated.
  816.   Then
  817.         echo $foo
  818.   gives the answer `255'.  It is possible to declare variables explicitly
  819.   to be integers, via
  820.         typeset -i foo
  821.   which has a different effect: namely the base used in the first
  822.   assignment (hexadecimal in the example) is subsequently used whenever
  823.   `foo' is displayed (although the internal representation is unchanged).
  824.   To ensure foo is always displayed in decimal, declare it as
  825.         typeset -i 10 foo
  826.   which requests base 10 for output.  You can change the output base of an
  827.   existing variable in this fashion.  Using the `$[ ... ]' method will
  828.   always display in decimal.
  829.  
  830.  
  831. C7) How do I get a newline in my prompt?
  832.  
  833.   You can place a literal newline in quotes, i.e.
  834.         PROMPT="Hi Joe,
  835.         what now?%# "
  836.   If you have the bad taste to set the option cshjunkiequotes, which
  837.   inhibits such behaviour, you will have to bracket this with
  838.   `unsetopt cshjunkiequotes' and `setopt cshjunkiequotes', or put it in
  839.   your .zshrc before the option is set.
  840.  
  841.   Arguably the prompt code should handle `print'-like escapes.  Feel
  842.   free to write this :-).
  843.  
  844.  
  845. C8) Why does `bindkey ^a command-name' or 'stty intr ^-' do something funny?
  846.  
  847.   You probably have the extendedglob option set in which case ^ and #
  848.   are metacharacters.  ^a matches any file except one called a, so the
  849.   line is interpreted as bindkey followed by a list of files.  Quote the
  850.   ^ with a backslash or put quotation marks around ^a.
  851.  
  852.  
  853. C9) Why can't I bind \C-s and \C-q any more?
  854.  
  855.   The control-s and control-q keys now do flow control by default,
  856.   unless you have turned this off with `stty -ixon' or redefined the
  857.   keys which control it with `stty start' or `stty stop'.  (This is
  858.   done by the system, not zsh; the shell simply respects these
  859.   settings.)  In other words, \C-s stops all output to the terminal,
  860.   while \C-q resumes it.
  861.  
  862.   There is an option NO_FLOW_CONTROL to stop zsh from allowing flow
  863.   control and hence restoring the use of the keys: put `setopt
  864.   noflowcontrol' in .zshrc.
  865.  
  866.  
  867. C10) How do I execute command `foo' within function `foo'?
  868.  
  869.   The command `command foo' does just that.  You don't need this with
  870.   aliases, but you do with functions.  Note that error messages like
  871.         zsh: job table full or recursion limit exceeded
  872.   are a good sign that you tried calling `foo' in function `foo' without
  873.   using `command'.
  874.  
  875.  
  876. C11) Why do history substitutions with single bangs do something funny?
  877.  
  878.   If you have a command like "echo !-2:$ !$", the first history
  879.   substitution then sets a default to which later history substitutions
  880.   with single unqualified bangs refer, so that !$ becomes equivalent to
  881.   !-2:$.  The option CSH_JUNKIE_HISTORY makes all single bangs refer
  882.   to the last command.
  883.  
  884.  
  885. C12) Why does zsh kill off all my background jobs when I logout?
  886.  
  887.   Simple answer: you haven't asked it not to.  Zsh (unlike [t]csh) gives
  888.   you the option of having background jobs killed or not: the `nohup'
  889.   option exists if you don't want them killed.  Note that you can always
  890.   run programs with `nohup' in front of the pipeline whether or not the
  891.   option is set, which will prevent that job from being killed on
  892.   logout.  (Nohup is actually an external command.)
  893.  
  894.   The `disown' builtin is very useful in this respect: if zsh informs
  895.   you that you have background jobs when you try to logout, you can
  896.   `disown' all the ones you don't want killed when you exit.  This is
  897.   also a good way of making jobs you don't need the shell to know about
  898.   (such as commands which create new windows) invisible to the shell.
  899.  
  900.  
  901. C13) How do I list all my history entries?
  902.  
  903. Tell zsh to start from entry 1: `history 1'.  Those entries at the
  904. start which are no longer in memory will be silently omitted.
  905.  
  906.  
  907. Section D:  The mysteries of completion
  908.  
  909. Programmable completion using the `compctl' command is one of the most
  910. powerful, and also potentially confusing, features of zsh; here I give
  911. a short introduction.  There is a set of example completions supplied
  912. with the source in Misc/compctl-examples; completion definitions for
  913. many of the most obvious commands can be found there.
  914.  
  915. D1) What is completion?
  916.  
  917.   `Completion' is where you hit a particular command key (TAB is the
  918.   standard one) and the shell tries to guess the word you are typing
  919.   and finish it for you --- a godsend for long file names, in
  920.   particular, but in zsh there are many, many more possibilities than
  921.   that.
  922.  
  923.   There is also a related process, `expansion', where the shell sees
  924.   you have typed something which would be turned by the shell into
  925.   something else, such as a variable turning into its value ($PWD
  926.   becomes /home/users/mydir) or a history reference (!! becomes
  927.   everything on the last command line).  In zsh, when you hit TAB it
  928.   will look to see if there is an expansion to be done; if there is,
  929.   it does that, otherwise it tries to perform completion.  Expansion
  930.   is generally fairly intuitive and not under user control; for the
  931.   rest of the section I will discuss completion only.
  932.  
  933.  
  934. D2) What sorts of things can be completed?
  935.  
  936.   The simplest sort is filename completion, mentioned above.  Unless
  937.   you have made special arrangements, as described below, then after
  938.   you type a command name, anything else you type is assumed by the
  939.   completion system to be a filename.  If you type part of a word and
  940.   hit TAB, zsh will see if it matches the first part a file name and
  941.   if it does it will automatically insert the rest.
  942.  
  943.   The other simple type is command completion, which applies
  944.   (naturally) to the first word on the line.  In this case, zsh
  945.   assumes the word is some command to be executed lying in your $PATH
  946.   and try to complete that.
  947.  
  948.   Other forms of completion have to be set up by special arrangement.
  949.   See the manual entry for compctl for a list of all the flags:  you
  950.   can make commands complete variable names, user names, job names,
  951.   etc., etc.
  952.  
  953.   For example, one common use is that you have an array variable,
  954.   $hosts, which contains names of other machines you use frequently on
  955.   the network:
  956.         hosts=(fred.ph.ku.ac.uk snuggles.floppy-bunnies.com here.there.edu)
  957.   then you can tell zsh that when you use telnet (or ftp, or ...), the
  958.   argument will be one of those names:
  959.         compctl -k hosts telnet ftp ...
  960.   so that if you type `telnet fr' and hit TAB, the rest of the name
  961.   will appear by itself.
  962.  
  963.   An even more powerful option to compctl (-g) is to tell zsh that
  964.   only certain sorts of filename are allowed.  The argument to -g is
  965.   exactly like a glob pattern, with the usual wildcards `*', `?', etc.
  966.   In the compctl statement it needs to be quoted to avoid it being
  967.   turned into filenames straight away.  For example,
  968.         compctl -g '*.(ps|eps)' ghostview
  969.   tells zsh that if you type TAB on an argument after a ghostview
  970.   command, only files ending in `.ps' or `.eps' should be considered
  971.   for completion.
  972.  
  973.   Note that flags may be combined; if you have more than one, all the
  974.   possible completions for all of them are put into the same list, all
  975.   of them being possible completions.  So
  976.         compctl -k hosts -f rcp
  977.   tells zsh that rcp can have a hostname or a filename after it.  (You
  978.   really need to be able to handle host:file, which is where
  979.   programmable completion comes in, see D4).)
  980.  
  981.  
  982. D3) How does zsh deal with ambiguous completions?
  983.  
  984.   Often there will be more than one possible completion: two files
  985.   start with the same characters, for example.  Zsh has a lot of
  986.   flexibility for what it does here via it's options.  The default is
  987.   for it to beep and completion to stop until you type another
  988.   character.  You can type ^D to see all the possible completions.
  989.   This can be changed by the following options, among others (1) with
  990.   nobeep set, that annoying beep goes away (2) with autolist set, when
  991.   the completion is ambiguous you get a list without having to type
  992.   ^D, (3) with menucomplete set, one completion is always inserted
  993.   completely, then when you hit TAB it changes to the next, and so on
  994.   until you get back to where you started (4) with automenu, you only
  995.   get the menu behaviour when you hit TAB again on the ambiguous
  996.   completion.  Combinations of these are possible.
  997.  
  998.  
  999. D4) How do I get started with programmable completion?
  1000.  
  1001.   Finally, the hairiest part of completion.  It is possible to get zsh
  1002.   to consider different completions not only for different commands,
  1003.   but for different words of the same command, or even to look at
  1004.   other words on the command line (for example, if the last word was a
  1005.   particular flag) and decide then.
  1006.  
  1007.   There are really two sorts of things to worry about.  The simpler is
  1008.   alternative completion:  that just means zsh will try one
  1009.   alternative, and only if there are no possible completions try the
  1010.   next.  For example
  1011.         compctl -g '*.ps' + -f lpr
  1012.   says that after lpr you'd prefer to find only `.ps' files, so if
  1013.   there are any, only those are used, but if there aren't any, any
  1014.   old file is a possibility.  You can also have a + with no flags
  1015.   after it, which tells zsh that it's to treat the command like any
  1016.   other if nothing was found.  That's only really useful if your
  1017.   default completion is fancy, i.e. you have done something with
  1018.   `compctl -D' to tell zsh how commands which aren't specially handled
  1019.   are to have their arguments completed.
  1020.  
  1021.   The second sort is the hard one.  Following a `-x', zsh expects that
  1022.   the next thing will be some completion code, which is a single
  1023.   letter followed by an argument in square brackets.  For example
  1024.   'p[1]': `p' is for position, and the argument tells it to look at
  1025.   position 1; that says that this completion only applies to the word
  1026.   immediately after the command.  You can also say 'p[1,3]' which says
  1027.   the completion only applies to the word if it's between the first
  1028.   and third words, inclusive, after the command, and so on.  See the
  1029.   list in the `compctl' manual entry for a list of these conditions:
  1030.   some conditions take one argument in the square brackets, some two.
  1031.   Usually, negative numeric arguments count backwards from the end
  1032.   (for example, 'p[-1]' applies to the last word on the line).
  1033.  
  1034.   The condition is then followed by the flags as usual (as in D2)),
  1035.   and possibly other condition/flag sets following a single -; the
  1036.   whole lot ends with a double -- before the command name.  In other
  1037.   words, each extended completion section looks like this:
  1038.         -x <pattern> <flags>... [ - <pattern> <flags>... ...] --
  1039.  
  1040.   Let's look at rcp again: this assumes you've set up $hosts as above.
  1041.   This uses the `n[<n>,<string>]' flag, which tells zsh to look for
  1042.   the <n>'th occurrence of <string> in the word, ignoring anything up
  1043.   to and including that.  We'll use it for completing the bits of
  1044.   rcp's `user@host:file' combination.  (Of course, the file name is on
  1045.   the local machine, not `host', but let's ignore that; it may still
  1046.   be useful.)
  1047.         compctl -k hosts -S ':' + -f -x 'n[1,:]' -f - \
  1048.           'n[1,@]' -k hosts -S ':' -- rcp
  1049.   This means: (1) try and complete a hostname (the bit before the
  1050.   `+'), if successful add a `:' (-S for suffix); (2) if that fails
  1051.   move on to try the code after the `+':  look and see if there is a
  1052.   `:' in a word (the `n[1,:]'); if there is, complete filenames (-f)
  1053.   after the first of them; (3) otherwise look for an `@' and complete
  1054.   hostnames after the first of them (the `n[1,@]'), adding a `:' if
  1055.   successful; (4) if all else fails use the -f before the `-x' and try
  1056.   to complete files.
  1057.  
  1058.   So the rules for order are (1) try anything before a `+' before
  1059.   anything after it (2) try the conditions after a -x in order until
  1060.   one succeeds (3) use the default flags before the -x if none of the
  1061.   conditions was true.
  1062.  
  1063.   Different conditions can also be combined.  There are three levels
  1064.   of this (in decreasing order of precedence):
  1065.     i) multiple square brackets after a single condition give
  1066.       alternatives:  for example, 's[foo][bar]' says apply the
  1067.       completion if the word begins with `foo' or `bar',
  1068.    ii) spaces between conditions mean both must match:  for example,
  1069.       'p[1] s[-]' says this completion only applies for the first word
  1070.       after the command and only if it begins with a `-',
  1071.   iii) commas between conditions mean either can match:  for example,
  1072.       'c[-1,-f], s[-f]' means either the previous word (-1 relative to
  1073.       the current one) is -f, or the current word begins with -f ---
  1074.       useful to use the same completion whether or not the -f has a
  1075.       space after it.
  1076.  
  1077.   Here's a useless example just to show a general `-x' completion.
  1078.         compctl -f -x 'c[-1,-u][-1,-U] p[2], s[-u]' -u - \
  1079.           'c[-1,-j]' -P % -j -- foobar
  1080.   The way to read this is:  for command `foobar', look and see if (((the
  1081.   word before the current one is -u) or (the word before the current
  1082.   one is -U)) and (the current word is 2)) or (the current word begins
  1083.   with -u); if so, try to complete user names.  If the word before
  1084.   the current one is -j, insert the prefix `%' before the current word
  1085.   if it's not there already and complete job names.  Otherwise, just
  1086.   complete file names.
  1087.  
  1088.  
  1089. D5) And if programmable completion isn't good enough?
  1090.  
  1091.   ...then your last resort is to write a shell function to do it for
  1092.   you.  By combining the `-U' and `-K func' flags you can get almost
  1093.   unlimited power.  The `-U' tells zsh that whatever the completion
  1094.   produces is to be used, even if it doesn't fit what's there already
  1095.   (so that gets deleted when the completion is inserted).  The `-K
  1096.   func' tells zsh a function name.  The function is passed what's on
  1097.   the line already, but it can return anything it likes via the
  1098.   `reply' array, and this becomes the set of possible completions.
  1099.   The best way to understand this is to look at `multicomp' and other
  1100.   functions supplied with the zsh distribution.
  1101.  
  1102.  
  1103. Section Z:  The future of zsh
  1104.  
  1105. Z1) What bugs are currently known and unfixed? (Plus recent important changes)
  1106.  
  1107.   Here are some of the more well-known ones, very roughly in
  1108.   decreasing order of significance.  Many of these can also be counted
  1109.   against differences from ksh in question B1); note that this applies
  1110.   to the latest beta version and that simple bugs are often fixed
  1111.   quite quickly.  There is a file Etc/BUGS in the source distribution
  1112.   with more detail.
  1113.  
  1114.   Special variables won't be unset after e.g. `PATH=... read ...',
  1115.     i.e. if used with a builtin command or shell function.
  1116.   `time' is ignored with builtins and can't be used with {...}.
  1117.   `set -x' (`setopt xtrace') still has a few glitches.
  1118.   The :q modifier doesn't split words and -q and -x don't work for variables.
  1119.   In vi mode, `u' can go past the original modification point.
  1120.   The singlelinezle option has problems with prompts containing escapes.
  1121.   The `r' command does not work inside $(...) or `...` expansions.
  1122.  
  1123.   Note that a few recent changes introduce incompatibilities (these
  1124.   are not bugs):
  1125.   From 2.6.beta21, <> performs redirection of input and output to the
  1126.     specified file.  For numeric globs, you now need <->.
  1127.   From 2.6.beta20, the command line qualifiers exec, noglob, command,
  1128.     - are now treated more like builtin commands:  previously they
  1129.     were syntactically special.  This should make it easier to perform
  1130.     tricks with them (disabling, hiding in parameters, etc.).
  1131.   The current beta version now uses ~'s for directory stack
  1132.     substitution instead of ='s.  This is for consistency:  all other
  1133.     directory substitution (~user, ~name, ~+, ...) used a tilde, while
  1134.     =<number> caused problems with =program substitution.
  1135.   The `HISTLIT' option was broken in various ways and has been removed:
  1136.     the rewritten history mechanism doesn't alter history lines, making
  1137.     the option unnecessary.
  1138.   History expansion is disabled in single-quoted strings, like other
  1139.     forms of expansion -- hence exclamation marks there should not be
  1140.     backslashed.
  1141.   The `HISTCHARS' variable is now `histchars'.  Currently both are
  1142.     tied together for compatibility.
  1143.   An option CSH_JUNKIE_PAREN has proved necessary for the syntax `if (
  1144.     <condition> ) <code>' and for similar `for' and `while' (but not
  1145.     `foreach') commands.  This is because it is valid Bourne/Korn shell
  1146.     syntax to have a subshell command immediately after if, and the
  1147.     default syntax should be compliant with that.
  1148.   You also need CSH_JUNKIE_PAREN if you want to use the syntax
  1149.     `if [[ ... ]] command' (maybe with `command' being in the form `{
  1150.     command1; ...}'; this was mainly here for csh compatibility.
  1151.     Remember you can use `[[ ... ]] && command' to do the same thing.
  1152.   Assignment of `...` and $(...) to variables in the form `foo=$(...)'
  1153.     is now always scalar; previously the command output was split and
  1154.     array assignment performed if more than one word resulted.  You
  1155.     can still generate an array vie `foo=($(...))', which was always
  1156.     the safe way of doing it.  Again, this is for Bourne/Korn
  1157.     compliance.  (Note the same is true for globbing, as mentioned
  1158.     in B1) above.)
  1159.   The -h option to compctl has been removed (use `-k hosts' for the
  1160.     same effect); automatic handling of hosts after '@' has been removed
  1161.     (use e.g. `compctl -u -x "n[-1,@]" -k hosts -- finger').
  1162.   Handling of backslashes in `echo' and `print' has changed.
  1163.   umask's behaviour with respect to symbolic operators has reversed
  1164.     (and is now ksh-compatible).
  1165.   The option CSH_JUNKIE_TILDE has been upgraded to GLOB_SUBST: instead
  1166.     of just ~'s and ='s, all characters become eligible for file
  1167.     expansion and globbing when the option is set.  (The option was
  1168.     not present in 2.3 at all.)
  1169.   The corresponding one-time switch ${~...}, together with ${^.,.}
  1170.     and ${=...}, now force the corresponding options on for the
  1171.     evaluation, rather than toggling (double the character to force off).
  1172.   "${#foo}" (with the quotes) now gives an array length if `foo' is an
  1173.     array.  ("${(c)#foo}" gives the total character length.)
  1174.   The PROMPT_SUBST option now performs backquote expansion -- hence
  1175.     you should quote these in prompts.  (SPROMPT has changed as a result.)
  1176.   
  1177.  
  1178.  
  1179. Z2) Where do I report bugs, get more info / who's working on zsh?
  1180.  
  1181.   The shell is being maintained by various (entirely self-appointed)
  1182.   subscribers to the mailing list,
  1183.         zsh-workers@math.gatech.edu
  1184.   so any suggestions, complaints, questions and matters for discussion
  1185.   should be sent there.  If you want someone to mail you directly, say
  1186.   so.  Most patches to zsh appear there first.
  1187.  
  1188.   Two progressively lower volume lists exist, one with messages
  1189.   concerning the use of zsh,
  1190.         zsh-users@math.gatech.edu
  1191.   and one just containing announcements:  about releases, about major
  1192.   changes in the shell, or this FAQ, for example,
  1193.         zsh-announce@math.gatech.edu
  1194.   (posting to the last one is currently restricted).
  1195.  
  1196.   Note that you should only join one of these lists:  people on
  1197.   zsh-workers receive all the lists, and people on zsh-users will
  1198.   also receive the announcements list.
  1199.  
  1200.   The lists are handled by an automated server.  The instructions for
  1201.   zsh-announce and zsh-users are the same as for zsh-workers: just
  1202.   change zsh-workers to whatever in the following.
  1203.  
  1204.   To join zsh-workers, send email to
  1205.         zsh-workers-request@math.gatech.edu
  1206.   with the *subject* line (this is a change from the old list)
  1207.         subscribe <your-email-address>
  1208.   e.g.
  1209.         Subject:  subscribe P.Stephenson@swansea.ac.uk
  1210.   and you can unsubscribe in the same way.
  1211.  
  1212.   The list maintainer, Richard Coleman, can be reached at
  1213.         comeman@math.gatech.edu
  1214.  
  1215.   The list (everything since May 1992) is archived in
  1216.         ftp://ftp.sterling.com/zsh/zsh-list/YY-MM
  1217.   where YY-MM are the year and month in digits.  A useful World Wide
  1218.   Web interface to recent mailings is currently kept at
  1219.         http://www-stud.enst.fr/~tardieu/mailarchive/zsh-list/index.html
  1220.   by Samuel Tardieu.
  1221.  
  1222.   Of course, you can also post zsh queries to the Usenet group
  1223.   comp.unix.shell; if all else fails, you could even e-mail me.
  1224.  
  1225.  
  1226. Z3) What's on the wish-list?
  1227.  
  1228.   Mostly, a lot of the code needs a major clean-up: particular
  1229.   offenders are the history code (hist.c: this is under way),
  1230.   parameter code (params.c) and substitution code (subst.c).  A more
  1231.   efficient set of code for lexing/parsing/execution might also be an
  1232.   advantage.  Volunteers are particularly welcome for these tasks.
  1233.  
  1234.   Ksh/sh compatibility could be improved; this is a useful long term goal.
  1235.   Option for glob qualifiers to follow perl syntax.
  1236.   Binding of shell functions (or commands?) to key strokes --
  1237.     requires some way of accessing the editing buffer from functions
  1238.     and probably of executing zle functions as a command.
  1239.   trap '...' FOO should be eval'd rather than called as a function.
  1240.   `PATH=' should clear the PATH:  it inserts `.'; use `unset PATH' or
  1241.     `path=()' for the time being.  This is not really a bug as the .
  1242.     would be used internally in any case (cf. ksh).
  1243.   Users should be able to create their own foopath/FOOPATH array/path
  1244.     combinations.
  1245.  
  1246.  
  1247. Acknowledgments:
  1248.  
  1249. Thanks to zsh-list, in particular Bart Schaefer, for suggestions
  1250. regarding this document.  Zsh has been in the hands of archivists Jim
  1251. Mattson, Bas de Bakker, Richard Coleman and Zoltan Hidvegi, and the
  1252. mailing list has been run by Peter Gray, Rick Ohnemus and Richard
  1253. Coleman, all of whom deserve thanks.  The world is eternally in the
  1254. debt of Paul Falstad for inventing zsh in the first place (though the
  1255. wizzo extended completion is by Sven Wishnowsky).
  1256.  
  1257.  
  1258. Copyright Information:
  1259.  
  1260. This document is copyright (C) P.W. Stephenson, 1995. This text
  1261. originates in the U.K. and the author asserts his moral rights under
  1262. the Copyrights, Designs and Patents Act, 1988.
  1263.  
  1264. Permission is hereby granted, without written agreement and without
  1265. license or royalty fees, to use, copy, modify, and distribute this
  1266. documentation for any purpose, provided that the above copyright
  1267. notice appears in all copies of this documentation.  Remember,
  1268. however, that this document changes monthly and it may be more useful
  1269. to provide a pointer to it rather than the entire text.  A suitable
  1270. pointer is "information on the Z-shell can be obtained on the World
  1271. Wide Web at URL http://www.mal.com/zsh/".
  1272.